home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 011 / adikit.arc / IWAIT.ASM < prev    next >
Assembly Source File  |  1986-12-01  |  3KB  |  113 lines

  1. ;
  2. ;    Install    resident program and service interrupts
  3. ;
  4. ;    This routine supports the development of installable
  5. ;    programs in Lattice C.    A program which    is intended to be
  6. ;    made an    installable INT    routine    is written in -P model
  7. ;    Lattice.  After    it initialises,    it calls, in a processing
  8. ;    loop:
  9. ;
  10. ;    while (1) {        /* Loop    processing requests */
  11. ;       iwait(<vec>,    &resreg, &reqreg);
  12. ;       ... process request ...
  13. ;    }
  14. ;
  15. ;    <vec> is the interrupt vector which will be used to call the
  16. ;    installed program.  RESREG and REQREG are instances of a structure
  17. ;    declared as:
  18. ;
  19. ;    struct regparam    {
  20. ;       unsigned ax,    bx, cx,    dx;
  21. ;    };
  22. ;
  23. ;    On the first call, the program will be installed and will
  24. ;    remain in memory until summoned    by an INT to the designated
  25. ;    vector <vec>.  When the    INT occurs, IWAIT will return with
  26. ;    REQREG containing the values in    AX through DX when the INT
  27. ;    was executed.  After the program processes the request,    it
  28. ;    may load values    into the RESREG    structure and return to    the
  29. ;    IWAIT.    The values in RESREG will be returned in the registers
  30. ;       upon return from the caller's INT.
  31.  
  32.     include    dos.mac
  33.  
  34.     dseg    install
  35.     EXTRN    _tsize:WORD
  36.     endds    install
  37.  
  38.     pseg
  39.     public    iwait
  40.  
  41. firstime dw    1        ; first    time flag
  42. rss    dw    0        ; save stack segment
  43. rsp    dw    0        ; save stack pointer
  44. css     dw      0               ; caller's stack segment
  45. csp     dw      0               ; caller's stack pointer
  46.  
  47. iwait    proc    far
  48.     push    bp
  49.     mov    bp,sp        ; set our arg pointer
  50.     push    ds        ; save important registers
  51.     push    es
  52.     push    bp        ; save argument    pointer
  53.     cmp    firstime,0    ; is this the first call ?
  54.     je    insnft        ; no.  skip setup
  55.     mov    firstime,0    ; mark not first time
  56.     mov    rss,ss        ; save stack segment
  57.     mov    rsp,sp        ; save stack pointer
  58.     mov    bx,args        ; load interrupt vector
  59.     shl    bx,1        ; * 2
  60.     shl    bx,1        ; * 4
  61.     mov    ax,0        ; clear    accumulator
  62.     mov    es,ax        ; address base page
  63.     mov    cx,offset intrap ; load    interrupt handler address
  64.     mov    es:[bx],cx    ; store    trap address
  65.     mov    es:[bx+2],cs    ; store    our segment
  66.     mov    ah,31h        ; load keep process code
  67.     mov    al,0        ; load normal termination
  68.     mov    dx,_tsize    ; load length to preserve
  69.     int    21h        ; terminate and    stay resident
  70.  
  71. insnft:    mov    si,args+2    ; load source registers
  72.     mov    ax,[si]        ; load AX
  73.     mov    bx,[si+2]    ; load BX
  74.     mov    cx,[si+4]    ; load CX
  75.     mov    dx,[si+6]    ; load DX
  76.     cli            ; prevent interrupts
  77.         mov     ss,css          ; load caller's stack segment
  78.         mov     sp,csp          ; load caller's stack pointer
  79.     sti            ; enable interrupts
  80.     pop    bp        ; save base page
  81.     pop    es        ; restore ES
  82.     pop    ds        ; restore DS
  83.     iret            ; return to caller
  84.  
  85. ;    Totally    awesome!  We just got an interrupt call    from the
  86. ;    vector.     Restore the context we    were running in    and return
  87. ;    as if from the last call.
  88.  
  89. intrap:    push    ds        ; save user data segment
  90.     push    es        ; save user extra segment
  91.     push    bp        ; save frame pointer
  92.     mov    css,ss        ; save stack segment
  93.     mov    csp,sp        ; save stack pointer
  94.     mov    ss,rss        ; restore our stack segment
  95.     mov    sp,rsp        ; restore our stack pointer
  96.     sti            ; enable interrupts
  97.     pop    bp        ; restore argument pointer
  98.     pop    es        ; restore ES
  99.     pop    ds        ; restore DS
  100.     cld            ; set the Goddam increment bit !
  101.     mov    si,args+4    ; load result register pointer
  102.     mov    [si],ax        ; store    AX
  103.     mov    [si+2],bx    ; save BX
  104.     mov    [si+4],cx    ; save CX
  105.     mov    [si+6],dx    ; save DX
  106.         pop     bp              ; restore caller's stack frame
  107.     ret            ; return
  108.  
  109. iwait    endp
  110.  
  111.     endps
  112.     end
  113.